<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link type="text/css" href="../../resource/ystfiles/wapcommon.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../../resource/ystfiles/fapiao.css">
    <link rel="stylesheet" href="../../resource/ystfiles/weuimin.css">
    <style>
    	body{
    		
    	}
    </style>
</head>
<body>
	<header id="statusBar">
		<div class="header">
			<div class="return">
				<img src="../../image/back.png" tapmode="presshover" style="left: 0" onclick="toindex()">
			</div>
			<div class="tittle">
				服务人员
			</div>
		</div>
	</header>
	<div id="contant" style="height:563px">
		<div class="bg">
			<div style="width:100%" class="w50 fl"><img id="activeScan" class="center" src="../../image/tabBar/ewm_sm.png" style="display: block;"><p class="p1 tc">扫一扫</p></div>
		</div>
		<!-- 加载动画 -->
		<div id="loadingToast" style="display:none;">
			<div class="weui-mask_transparent"></div>
			<div class="weui-toast">
				<i class="weui-loading weui-icon_toast"></i>
				<p class="weui-toast__content">数据加载中...</p>
			</div>
		</div>
		<div id="CK_boxs">
		</div>
		<div style="width: 90%" class="FP_btn" onclick="tjCkxx();">
			<a style="display: inline-block;display: -moz-inline-stack;width: 100%;color: #888;" ><strong style="font-size: 20px;">+</strong>&nbsp;手动添加车辆信息</a>
		</div>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../resource/jquery1.js"></script>
<script type="text/javascript" charset="UTF-8" src="../../script/naes.js"></script>
<script type="text/javascript" src="../../script/constants.js"></script>
<script type="text/javascript">
	apiready = function(){
		api.parseTapmode();
		$api.fixStatusBar($api.dom('header'));
		if(api.systemType=="ios"){
			document.getElementById("statusBar").style.background="#298cb4";
		}
		$("#loadingToast").show();
		api.addEventListener({
			name: 'addCk'
		}, function(ret, err) {
		 	window.location.reload();
		});
		api.addEventListener({
	        name:'delCk'
        },function(ret,err){
        	window.location.reload();
        });
        api.addEventListener({
	        name:'updCk'
        },function(ret,err){
        	window.location.reload();
        });
		var callback = function(ret, err){
            if (ret) {
	            if(ret.success){
	            	xlist=ret.xlist;
		        	for(var i=0;i<xlist.length;i++){
						var s = ""; 
						var AUDIT_STATUS;
						if(xlist[i].IS_AUDIT==0){
							AUDIT_STATUS="未审核";
						}else if(xlist[i].IS_AUDIT==1){
							AUDIT_STATUS="审核通过";
						}else if(xlist[i].IS_AUDIT==-1){
							AUDIT_STATUS="审核拒绝";
						}
						var num = "";
						s += "<div class='FP_box clearfix' style='background: #27a8fa;'> "+
						     "	<div onclick='showDetail("+xlist[i].ID+")'  class='fl' style='width: 100%;padding-bottom:5px;'> "+
						     "		<h6><a style='color:#fff '>"+ xlist[i].DRIVER_NAME+"</a></h6> ";
						if(xlist[i].PLATE_NUM == undefined || xlist[i].PLATE_NUM == "undefined"){
						   num = "无车辆人员";
						}else{
						   num = xlist[i].PLATE_NUM;
						}
		    			s += "		<p style='color:#fff;font-size:12px;font-family:微软雅黑;' id='test'>"+num+"</p> "+
		    				 "		<p style='color:#fff;font-size:12px;font-family:微软雅黑;' id='test'>"+AUDIT_STATUS+"</p> "+
		    				 "  </div> "+
		    				 "</div>";
						
						$("#CK_boxs").append(s);
		        	}
		        	$("#loadingToast").hide();
	            }else{
	            	$("#loadingToast").hide();
					api.alert({msg:'载入错误！原因：'+ret.msg});
	            }
			 } else {
			    $("#loadingToast").hide();
				api.alert({msg:'载入错误！原因：'+err.msg});
			 } 
	    };
	    var dl_phone = $api.getStorage("dl_phone");
		if (typeof(dl_phone) == "undefined" || dl_phone == "undefined" || dl_phone == "" || dl_phone == null) {
		   api.alert({
				msg: '登录已过期，请重新登录！'
			}, function(ret, err) {
				api.openWin({
					name: '跳转登陆',
					url: '../login.html'
				});
			});
		}else{
			var content = {"dl_phone":dl_phone};
	    	apiAjax(JSON.stringify(content),url.getSceneryListInfo,callback);
		}
	};
	
	function toindex(){
		api.closeWin();
	}
	
	function tjCkxx(){
		api.openWin({
	        name: '添加乘客信息',
	        url: 'addCkInfo.html',
	        pageParam:{
	        	cltj_type : 0
	        }
        });
	}
	
	function showDetail(id){
		api.openWin({
	        name: 'editCkInfo',
	        url: 'editCkInfo.html',
	        pageParam:{
	        	cl_id : id,
	        	clck_type : 0
	        }
        });
	}
	
	$("#activeScan").click(function(){
		scanQRCode();
	});
	
	function scanQRCode(){
		var FNScanner = api.require('FNScanner');
	    FNScanner.openScanner({
	      autorotation: true
	    }, function(ret, err) {
		    setTimeout(function(){
		        if(ret){
			  		if(ret.eventType=="success"){
			  			var strs = ret.content;
			  			if(strs.length>0){
			  				if(strs.indexOf("SCHX_CLGL")<0){
			  					api.alert({msg:'未知二维码！'});
			  				}else{
			  					var driverName="";
			  					var driverCard="";
			  					var plateNum="";
			  					var driverTelephone="";
			  					var passengerNames="";
			  					var passengerTelephones="";
			  					var passengerIdcards="";
			  					var enterDate = "";
			  					var leaveDate = "";
			  					var enterReason = "";
			  					var arrayMain = strs.split("&");
			  					var arrayDetail = arrayMain[1].split("=");
			  					var id = arrayDetail[1];
			  					var uiId;
								var UILoading = api.require('UILoading');
								UILoading.flower({
						            center: {
							            x: api.winWidth/2.0,
							            y: api.winHeight/2.0
						            },
						            size: 30,
						            fixed: true,
						            mask: "rgba(0,0,0,0.5)"
						        },function(ret,err){
						        	uiId = ret.id;
						        });
			  			        var callback = function(ret,err){
			  			        console.log("ret:"+JSON.stringify(ret));
					            if(ret){
					            	if(ret.success){
					            		var main = ret.main;
					            		var detail = ret.detail;
					            		driverName = main.DRIVER_NAME;
					            		driverCard = main.DRIVER_CARD;
					            		if(main.PLATE_NUM != undefined && main.PLATE_NUM != "undefined"){
					            		   $("#PLATE_NUM").val(main.PLATE_NUM);
					            		}
					            		driverTelephone = main.DRIVER_TELEPHONE;
					            		var PASSENGER_NAMES="";
					            		var PASSENGER_TELEPHONES="";
					            		var PASSENGER_IDCARDS="";
					            		if(detail.length>0){
					            			var count=0;
					            			for(var i=0;i<detail.length;i++){
					            				var PASSENGER_TELEPHONE = detail[i].PASSENGER_TELEPHONE;
					            				if(PASSENGER_TELEPHONE==null||PASSENGER_TELEPHONE==undefined){
					            					PASSENGER_TELEPHONE="";
					            				}
					            				if(count==0){
					            				    PASSENGER_IDCARDS+=detail[i].PASSENGER_IDCARD;
					            					PASSENGER_NAMES+=detail[i].PASSENGER_NAME;
					            					PASSENGER_TELEPHONES+=PASSENGER_TELEPHONE;
					            					count++;
					            				}else{
					            				    PASSENGER_IDCARDS+=","+detail[i].PASSENGER_IDCARD;
					            					PASSENGER_NAMES+=","+detail[i].PASSENGER_NAME;
					            					PASSENGER_TELEPHONES+=","+PASSENGER_TELEPHONE;
					            				}
					            			}
					            		}
					  					passengerNames=PASSENGER_NAMES;
					  					passengerTelephones=PASSENGER_TELEPHONES;
					  					passengerIdcards=PASSENGER_IDCARDS;
					  					if(main.PLATE_NUM != undefined || main.PLATE_NUM != "undefined"){
					  					    plateNum = main.PLATE_NUM;
					  					}
					  					enterDate = main.ENTER_DATE;
					  					leaveDate = main.LEAVE_DATE;
					  					enterReason = main.ENTER_REASON;
					        			UILoading.closeFlower({
							                id: uiId
							            });
							            console.log("driverName:"+driverName);
							            console.log("driverCard:"+driverCard);
							            console.log("plateNum:"+plateNum);
							            api.openWin({
		                                  name: 'addCkInfo',
		                                  url: 'addCkInfo.html',
		                                  pageParam:{
		                                  	is_load_ck : 1,
									      	cltj_type : 0,
									      	driverName : driverName,
									      	driverCard : driverCard,
									      	plateNum : plateNum,
									      	driverTelephone : driverTelephone,
									      	passengerNames : passengerNames,
									      	passengerTelephones : passengerTelephones,
									      	passengerIdcards : passengerIdcards,
									      	enterDate : enterDate,
									      	leaveDate : leaveDate,
									      	enterReason : enterReason
									      }
	                                   });
					            	}else{
					            		api.alert({msg: "初始化失败！原因："+ret.msg});
					            	}
					            }else{
					            	UILoading.closeFlower({
						                id: uiId
						            });
					            	api.alert({msg:"初始化失败，原因："+err.msg});
					        	}
							};
							var content = {"id":id};
							apiAjax(JSON.stringify(content),url.getDriverInfo,callback);
//			  					for(var i=0;i<arrayMain.length;i++){
//			  						if(arrayMain[i].indexOf("DRIVER_NAME")>=0){
//			  							var arrayDetail = arrayMain[i].split("=");
//			  							driverName = arrayDetail[1];
//			  						}else if(arrayMain[i].indexOf("DRIVER_CARD")>=0){
//			  							var arrayDetail = arrayMain[i].split("=");
//			  							driverCard = arrayDetail[1];
//			  						}else if(arrayMain[i].indexOf("PLATE_NUM")>=0){
//			  							var arrayDetail = arrayMain[i].split("=");
//			  							plateNum = arrayDetail[1];
//			  						}else if(arrayMain[i].indexOf("DRIVER_TELEPHONE")>=0){
//			  							var arrayDetail = arrayMain[i].split("=");
//			  							driverTelephone = arrayDetail[1];
//			  						}else if(arrayMain[i].indexOf("PASSENGER_NAMES")>=0){
//			  							var arrayDetail = arrayMain[i].split("=");
//			  							passengerNames = arrayDetail[1];
//			  						}else if(arrayMain[i].indexOf("PASSENGER_TELEPHONES")>=0){
//			  							var arrayDetail = arrayMain[i].split("=");
//			  							passengerTelephones = arrayDetail[1];
//			  						}else if(arrayMain[i].indexOf("PASSENGER_IDCARDS")>=0){
//			  							var arrayDetail = arrayMain[i].split("=");
//			  							passengerIdcards = arrayDetail[1];
//			  						}else if(arrayMain[i].indexOf("ENTER_DATE")>=0){
//			  							var arrayDetail = arrayMain[i].split("=");
//			  							enterDate = arrayDetail[1];
//			  						}else if(arrayMain[i].indexOf("LEAVE_DATE")>=0){
//			  							var arrayDetail = arrayMain[i].split("=");
//			  							leaveDate = arrayDetail[1];
//			  						}else if(arrayMain[i].indexOf("ENTER_REASON")>=0){
//			  							var arrayDetail = arrayMain[i].split("=");
//			  							enterReason = arrayDetail[1];
//			  						}
//			  					}
			  				}
			  			}else{
			  				api.alert({msg:'没有扫描到相关信息！'});
			  			}
			  		}
   				 } else {
   				    api.alert({msg:"系统错误！原因："+err.msg});
   				 }
		   	},500); 
	    });
	}
</script>
</html>